var common = require("../../../public")
const app = getApp()
Page({
    data: {
        active: 0,
        userInfo: '',
        token: '',
        status: 2,
        pageNum: 1,
        pageSize: 20,
        lucky_list: [],
        isLoading: false
    },
    onLoad: function () {
        let that = this;

        wx.getStorage({
            key: 'user',
            success: function (res) {
                that.setData({
                    userInfo: res.data.user,
                    token: res.data.token,
                }, () => {
                    that.getMyStoreDrawOrderList()
                })
            },
            fail: function () {
                common.showLoginPage()
            }
        })
    },
    onReachBottom: function () {
        this.getMyStoreDrawOrderList();
    },
    tabsChange({
        detail
    }) {
        let that = this;
        let {
            index,
            name,
            title
        } = detail;

        that.setData({
            status: index == 0 ? 2 : 3,
            pageNum: 1,
            lucky_list: []
        }, () => {
            that.getMyStoreDrawOrderList()
        })
    },
    receiveMoney({
        currentTarget
    }) {
        let that = this;
        let tempJson = {
            userId: this.data.userInfo.id,
            token: this.data.token,
            orderId: currentTarget.dataset.orderid,
        }
        wx.showLoading({
            title: '加载中...',
            mask: true
        })
        common.post("/storeDraw/getApplyMoney", tempJson, function (res) {
            if (res.status === 200) {
                wx.showToast({
                    title: '领取成功',
                    icon: 'success',
                    duration: 2000
                })
                // getMyStoreDrawOrderList()
                that.setData({
                    pageNum:1,
                    lucky_list:[]

                },()=>{
                    that.getMyStoreDrawOrderList()
                })
               
            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error',
                    duration: 2000
                })
            }
        }, function () {
            wx.hideLoading()
        })
    },
    getMyStoreDrawOrderList() {
        let that = this;
        let tempJson = {
            userId: this.data.userInfo.id,
            token: this.data.token,
            status: this.data.status,
            pageNum: this.data.pageNum,
            pageSize: this.data.pageSize
        }

        this.setData({
            isLoading: true
        })
        common.post("/storeDraw/getMyStoreDrawOrderList", tempJson, function (res) {
            if (res.status === 200) {
                that.setData({
                    lucky_list: that.data.lucky_list.concat(res.data),
                    pageNum: that.data.pageNum + 1
                })
            } else { }
        }, function () {
            wx.hideLoading()
            that.setData({
                isLoading: false
            })
        })
    },
    toDetail(e) {

        // isreceiveapplymoney报名费 
        let {
            id,
            isreceiveapplymoney
        } = e.currentTarget.dataset
        wx.navigateTo({
            url: '/pages/draw/index?drawId=' + id + '&isReceiveApplyMoney=' + isreceiveapplymoney + 
            '&from=detail'
            ,
        })
    },
    listLoad() {
        console.log('111zzz')
    }
})
